package com.siwei.mes.service.experiment.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.experiment.ExperimentBatchRecord;
import com.siwei.mes.mapper.experiment.ExperimentBatchRecordMapper;
import com.siwei.mes.service.experiment.ExperimentBatchRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 试验台账快检信息(ExperimentBatchRecord)表服务实现类
 *
 * @author linzi
 * @since 2023-12-24 21:44:10
 */
@Service
public class ExperimentBatchRecordServiceImpl implements ExperimentBatchRecordService {
    @Resource
    private ExperimentBatchRecordMapper experimentBatchRecordMapper;

    @Override
    public Long create(ExperimentBatchRecord entity) {
        experimentBatchRecordMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(ExperimentBatchRecord entity) {
        ExperimentBatchRecord experimentBatchRecord = experimentBatchRecordMapper.selectByPrimaryKey(entity.getId());
        assertTrue(experimentBatchRecord == null, "试验台账快检信息信息不存在");
        experimentBatchRecordMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        ExperimentBatchRecord experimentBatchRecord = experimentBatchRecordMapper.selectByPrimaryKey(id);
        assertTrue(experimentBatchRecord == null, "试验台账快检信息信息不存在");
        experimentBatchRecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<ExperimentBatchRecord> getPage(PageQuery<ExperimentBatchRecord, ExperimentBatchRecord> query) {
        ExperimentBatchRecord searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> experimentBatchRecordMapper.getList(searchParam));
    }

    @Override
    public ExperimentBatchRecord loadById(Long id) {
        return experimentBatchRecordMapper.loadById(id);
    }

    @Override
    public List<ExperimentBatchRecord> getAll(ExperimentBatchRecord entity) {
        return experimentBatchRecordMapper.getList(entity);
    }
}
